const express = require('express');
const router = express.Router();
const dietController = require('../controllers/dietController');
const foodController = require('../controllers/foodController');
const recipeController = require('../controllers/recipeController');
const { protect } = require('../middleware/auth');

// 应用认证中间件到所有路由
router.use(protect);

// 食物相关路由 - 注意路由顺序：特定路由应放在 :id 参数路由之前
router.get('/foods/search', foodController.searchFoods);
router.get('/foods/recommended', foodController.getRecommendedFood);
router.get('/foods/categories', foodController.getFoodCategories);
router.get('/foods/tianapi/search', foodController.searchTianapiFood);
router.post('/foods/tianapi/save', foodController.saveTianapiFood);
router.get('/foods/:id', foodController.getFoodById);
router.post('/foods', foodController.addCustomFood);

// 餐食相关路由
router.get('/meals', dietController.getMealsByDate);
router.get('/meals/:id', dietController.getMealById);
router.post('/meals', dietController.addMeal);
router.put('/meals/:id', dietController.updateMeal);
router.delete('/meals/:id', dietController.deleteMeal);

// 食谱相关路由
router.get('/recipes/featured', recipeController.getFeaturedRecipes);
router.get('/recipes/search', recipeController.searchRecipes);
router.get('/recipes/suitable', recipeController.getRecipesBySuitability);
router.get('/recipes/tianapi/search', recipeController.searchTianapiRecipes);
router.post('/recipes/tianapi/save', recipeController.saveTianapiRecipe);
router.get('/recipes/recommend', recipeController.getRecipeRecommendations);
router.get('/recipes', recipeController.getRecipes);
router.get('/recipes/:id', recipeController.getRecipeById);

// 营养统计路由
router.get('/stats', dietController.getNutritionStats);

module.exports = router; 